<template>
  <div id="EquipmentBookingIngPage">
    <div v-if="false" class="search-wrapper">
      <div class="title-wrapper">
        <span class="title">设备筛选</span>
      </div>
      <div class="content-wrapper">
        <div class="search-item">
          <span class="item-label">设备名称</span>
          <el-input
            class="item-input"
            v-model="queryObj.keyword"
            placeholder="请输入设备名称"
            clearable
            @change="searchHandle"
          />
        </div>
        <div class="search-item">
          <span class="item-label">设备类型</span>
          <el-select
            class="item-input"
            v-model="queryObj.typeId"
            placeholder="请选择设备类型"
            clearable
            @change="searchHandle"
          >
            <el-option label="所有" :value="''" />
            <el-option
              v-for="item in equipmentTypeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </div>
        <div class="search-btn" @click="searchHandle">筛选</div>
      </div>
    </div>
    <div class="data-wrapper">
      <div class="title-wrapper">
        <span class="title">设备列表</span>
      </div>
      <div class="table-wrapper">
        <el-table
          :data="tableData"
          stripe
          fit
          class="self-stripe-table"
          height="100%"
        >
          <el-table-column type="index" label="序号" width="100" />
          <el-table-column prop="name" label="设备名称">
            <template #default="scope">
              <div class="equipment-name-wrapper">
                <img
                  :src="
                    (scope.row.photoList && scope.row.photoList[0]?.url) ||
                    require('@/assets/images/defaultDevice.png')
                  "
                  alt="设备图片"
                  class="equipment-photo"
                />
                <div class="equipment-info-wrapper">
                  <span class="equipment-name">
                    {{ scope.row.name }}
                  </span>

                  <span class="equipment-sn"> SN：{{ scope.row.code }} </span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="设备类型">
            <template #default="scope">
              <div>{{ scope.row.typeInfo?.name || "--" }}</div>
            </template>
          </el-table-column>
          <el-table-column prop="model" label="设备型号" />
          <el-table-column label="设备负责人">
            <template #default="scope">
              <div>{{ scope.row.chargeUserInfo?.name || "--" }}</div>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="设备状态">
            <template #default="scope">
              <div class="signal-status" :class="scope.row.status">
                {{ statusMap[scope.row.status] }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150">
            <template #default="scope">
              <div
                v-if="activeMenu === 'applyed'"
                class="table-btn"
                @click="bookingHandle(scope.row)"
              >
                去预约
              </div>
              <div
                v-if="activeMenu === 'apply' || activeMenu === 'booking'"
                class="table-btn"
                @click="auditProgressHandle(scope.row, activeMenu)"
              >
                查看审批进度
              </div>
              <div
                v-if="activeMenu === 'using' && scope.row.status === 'IDLE'"
                class="table-btn"
                @click="useDeviceHandle(scope.row)"
              >
                开始使用
              </div>
              <div
                v-if="activeMenu === 'using' && scope.row.status === 'IN_USE'"
                class="table-btn"
                @click="returnHandle(scope.row)"
              >
                归还
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 分页 -->
    <div v-if="pagination.totalPages > 1" class="pagination-wrapper">
      <el-pagination
        v-model="pagination.page"
        :total="pagination.totalElements"
        :page-size="pagination.size"
        background
        :hide-on-single-page="true"
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
      />
    </div>

    <!-- 预约设备弹框 -->
    <el-dialog
      class="self-dialog"
      v-model="bookingDialogVisible"
      title="预约设备"
      width="50%"
    >
      <div class="handle-message">
        您正在预约设备：{{ currentBookingRow?.name }}
      </div>
      <div v-if="existingReservations.length > 0" class="reservation-tips">
        <div class="tips-title">已预约时间段：</div>
        <div class="tips-content">
          <div
            v-for="(reservation, index) in existingReservations"
            :key="index"
            class="reservation-item"
          >
            {{ formatDate(reservation.reservationStartTime) }} 至
            {{ formatDate(reservation.reservationEndTime) }}
          </div>
        </div>
      </div>
      <el-form
        ref="bookingFormRef"
        :model="bookingForm"
        :rules="bookingFormRules"
        label-width="100px"
        label-position="right"
      >
        <el-form-item label="预约时间" prop="dateRange">
          <el-date-picker
            v-model="bookingForm.dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="x"
            style="width: 100%"
            :disabled-date="isDateDisabled"
          />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="bookingForm.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="使用位置" prop="location">
          <el-input
            v-model="bookingForm.location"
            placeholder="请输入使用位置"
          />
        </el-form-item>
        <el-form-item label="使用时长" prop="usageDurationDays">
          <el-input
            v-model="bookingForm.usageDurationDays"
            placeholder="请输入使用时长"
          />（天）
        </el-form-item>
        <el-form-item label="最大提前量" prop="maxAdvanceDays">
          <el-input
            v-model="bookingForm.maxAdvanceDays"
            placeholder="请输入最大提前量"
          />（天）
        </el-form-item>
        <el-form-item label="频次限制" prop="frequencyLimit">
          <el-input
            v-model="bookingForm.frequencyLimit"
            placeholder="请输入频次限制"
          />（次）
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="bookingDialogVisible = false">取消</el-button>
          <el-button
            type="primary"
            @click="submitBookingForm"
            :loading="bookingFormLoading"
            >确定</el-button
          >
        </span>
      </template>
    </el-dialog>

    <!-- 查看审批进度 -->
    <el-dialog
      class="self-dialog"
      v-model="auditProgressDialogVisible"
      title="查看申请审批进度"
      width="50%"
    >
      <div class="audit-progress-container">
        <div class="progress-steps">
          <div
            v-for="(step, index) in auditProgress"
            :key="index"
            class="progress-step"
            :class="step.status"
          >
            <div class="step-indicator">
              <div class="step-circle"></div>
              <div
                class="step-line"
                v-if="index < auditProgress.length - 1"
              ></div>
            </div>
            <div class="step-content">
              <div class="step-title">{{ step.stageDescription }}</div>
              <div class="step-time" v-if="step.approvalTime">
                {{ formatDate(step.approvalTime) || "" }}
              </div>
              <div class="step-handler" v-if="step.statusDescription">
                {{ step.statusDescription }}
              </div>
              <div class="step-comment" v-if="step.comment">
                【{{ step.comment }}】
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 查看预约审批进度 -->
    <el-dialog
      class="self-dialog"
      v-model="auditReservationProgressDialogVisible"
      title="查看预约审批进度"
      width="50%"
    >
      <div class="audit-progress-container">
        <div class="progress-steps">
          <div
            v-for="(step, index) in auditReservationProgress"
            :key="index"
            class="progress-step"
            :class="step.status"
          >
            <div class="step-indicator">
              <div class="step-circle"></div>
              <div
                class="step-line"
                v-if="index < auditReservationProgress.length - 1"
              ></div>
            </div>
            <div class="step-content">
              <div class="step-title">{{ step.approverInfo.name }}</div>
              <div class="step-time" v-if="step.approvalTime">
                {{ formatDate(step.approvalTime) || "" }}
              </div>
              <div class="step-handler" v-if="step.status">
                {{
                  reservationStatusMap[
                    step.status as keyof typeof reservationStatusMap
                  ]
                }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 归还 -->
    <el-dialog
      class="self-dialog"
      v-model="returnDialogVisible"
      title="归还设备"
      width="50%"
    >
      <div class="handle-message">
        您正在归还设备：{{ currentReturnRow?.name }}
      </div>
      <el-form
        ref="returnFormRef"
        :model="returnForm"
        label-width="100px"
        label-position="right"
      >
        <el-form-item label="备注" prop="returnNote">
          <el-input
            v-model="returnForm.returnNote"
            placeholder="请输入归还备注"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="returnDialogVisible = false">取消</el-button>
          <el-button
            type="primary"
            @click="submitReturnForm"
            :loading="returnLoading"
            >确定</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, defineProps, watch } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { formatDate } from "@/assets/js/utils";

import { ListResponseType, PaginationType } from "@/api/globalType";
import {
  getApplicationDetailAPI,
  AuditProgressType,
} from "@/api/service/deviceApplicant";

import {
  addReservationAPI,
  returnDeviceAPI,
  getReservationByIdAPI,
  updateUseStatusAPI,
  pageAPI,
} from "@/api/service/reservations";

import { getUserDevicesPageAPI } from "@/api/service/equipmentManage";

import { typesAPI } from "@/api/service/equipmentManage";
import { EquipmentType } from "@/api/types/equipment";

const userInfo = JSON.parse(localStorage.getItem("userInfo") || "{}");

const statusMap = ref<Record<string, string>>({
  IDLE: "空闲中",
  RESERVEING: "预约中",
  IN_USE: "使用中",
  // REPAIRING: "维护中",
  DAMAGED: "损坏",
  SCRAPPED: "报废",
});

// 获取设备类型列表
const equipmentTypeList = ref<EquipmentType[]>([]);
const equipmentTypeListLoading = ref(false);
function getEquipmentTypeList() {
  if (equipmentTypeListLoading.value) return;
  equipmentTypeListLoading.value = true;
  typesAPI()
    .then((res: any) => {
      equipmentTypeList.value = res.deviceTypes || [];
    })
    .catch(() => {
      ElMessage.error("获取设备类型列表失败");
    })
    .finally(() => {
      equipmentTypeListLoading.value = false;
    });
}
getEquipmentTypeList();

// 查询条件
const queryObj = ref({
  keyword: "",
  deviceTypeId: "",
  userCode: userInfo.userCode || "",
  applicationStatus: "",
  reservationStatus: "",
  typeId: "",
});

// 分页
const pagination = ref<PaginationType>({
  page: 1,
  size: 50,
  totalElements: 0,
  totalPages: 0,
});

// 表格数据
const tableData = ref<any[]>([]);

// API调用保护状态
const listApiLoading = ref(false);

function getEquipmentList() {
  // 防止并发调用
  if (listApiLoading.value) return;

  listApiLoading.value = true;
  const _params = {
    userCode: queryObj.value.userCode,
    applicationStatus: queryObj.value.applicationStatus,
    reservationStatus: queryObj.value.reservationStatus,
    page: pagination.value.page,
    size: pagination.value.size,
  };

  getUserDevicesPageAPI(_params)
    .then((_data: any) => {
      const data = _data as ListResponseType<any>;
      if (props.activeMenu === "applyed") {
        data.content = data.content.filter(
          (item: any) =>
            item.applicationProcesses[0].status === "APPROVED" &&
            item.reservationProcesses.length === 0
        );
      }
      tableData.value = data.content;
      pagination.value.page = data.page;
      pagination.value.size = data.size;
      pagination.value.totalElements = data.totalElements;
      pagination.value.totalPages = data.totalPages;
    })
    .catch(() => {
      ElMessage.error("获取设备列表失败");
    })
    .finally(() => {
      listApiLoading.value = false;
    });
}

const props = defineProps<{
  activeMenu: string;
}>();

// 监听 activeMenu 变化
watch(
  () => props.activeMenu,
  (newVal) => {
    if (newVal === "apply") {
      queryObj.value.applicationStatus = "APPROVING";
      queryObj.value.reservationStatus = "";
      pagination.value.page = 1;
      getEquipmentList();
    } else if (newVal === "applyed") {
      queryObj.value.applicationStatus = "APPROVED";
      queryObj.value.reservationStatus = "";
      pagination.value.page = 1;
      getEquipmentList();
    } else if (newVal === "booking") {
      queryObj.value.applicationStatus = "";
      queryObj.value.reservationStatus = "APPROVING";
      pagination.value.page = 1;
      getEquipmentList();
    } else if (newVal === "using") {
      queryObj.value.applicationStatus = "";
      queryObj.value.reservationStatus = "APPROVED";
      pagination.value.page = 1;
      getEquipmentList();
    }
  },
  { immediate: true }
);

// 筛选
function searchHandle() {
  pagination.value.page = 1;
  getEquipmentList();
}

// 分页大小变化
function sizeChangeHandle(size: number) {
  pagination.value.size = size;
  pagination.value.page = 1;
  getEquipmentList();
}
// 分页当前页变化
function currentChangeHandle(currentPage: number) {
  pagination.value.page = currentPage;
  getEquipmentList();
}

const applyDialogVisible = ref(false);

// 预约设备
const currentBookingRow = ref<EquipmentType>();
const bookingDialogVisible = ref(false);
const bookingFormRef = ref();
const bookingFormLoading = ref(false);
const bookingForm = ref({
  dateRange: [],
  userCode: "",
  deviceId: "",
  startTime: 0,
  endTime: 0,
  purpose: "",
  location: "",
  maxAdvanceDays: 1,
  usageDurationDays: 1,
  frequencyLimit: 1,
});

// 已预约时间段管理
const existingReservations = ref<any[]>([]);
const reservationsLoading = ref(false);

// 获取指定设备的已预约时间段
function getDeviceReservations(deviceId: string) {
  if (reservationsLoading.value) return;
  reservationsLoading.value = true;

  pageAPI({
    page: 1,
    size: 100, // 获取所有预约记录
    deviceId: deviceId,
    reservationStatus: "",
  })
    .then((res: any) => {
      res.content = res.content.filter(
        (item: any) =>
          item.reservationStatus === "APPROVING" ||
          item.reservationStatus === "APPROVED"
      );
      existingReservations.value = res.content;
    })
    .catch(() => {
      ElMessage.error("获取预约记录失败");
      existingReservations.value = [];
    })
    .finally(() => {
      reservationsLoading.value = false;
    });
}

// 检查日期是否与已预约时间冲突
function isDateDisabled(date: Date) {
  const dateTime = date.getTime();

  return existingReservations.value.some((reservation: any) => {
    const startTime = reservation.reservationStartTime;
    const endTime = reservation.reservationEndTime;

    // 检查日期是否在预约时间段内
    return dateTime >= startTime && dateTime <= endTime;
  });
}

function bookingHandle(row: any) {
  bookingDialogVisible.value = true;
  currentBookingRow.value = row;
  bookingForm.value = {
    dateRange: [],
    userCode: userInfo.userCode || "",
    deviceId: row.id || "",
    startTime: 0,
    endTime: 0,
    purpose: "",
    location: "",
    maxAdvanceDays: 1,
    usageDurationDays: 1,
    frequencyLimit: 1,
  };

  // 获取该设备的已预约时间段
  if (row.id) {
    getDeviceReservations(row.id);
  }
}
function submitBookingForm() {
  if (bookingFormLoading.value) return;
  bookingFormRef.value?.validate((valid: boolean) => {
    if (valid) {
      bookingFormLoading.value = true;
      addReservationAPI({
        userCode: bookingForm.value.userCode,
        deviceId: bookingForm.value.deviceId,
        startTime: bookingForm.value.dateRange[0],
        endTime: bookingForm.value.dateRange[1],
        purpose: bookingForm.value.purpose,
        location: bookingForm.value.location,
        maxAdvanceDays: bookingForm.value.maxAdvanceDays,
        usageDurationDays: bookingForm.value.usageDurationDays,
        frequencyLimit: bookingForm.value.frequencyLimit,
      })
        .then(() => {
          ElMessage.success("预约设备成功");
          resetBookingForm();
          getEquipmentList();
        })
        .catch((error) => {
          ElMessage.error(error.message);
        })
        .finally(() => {
          bookingFormLoading.value = false;
        });
    } else {
      ElMessage.error("请填写完整预约信息");
    }
  });
}
function resetBookingForm() {
  bookingForm.value = {
    dateRange: [],
    userCode: "",
    deviceId: "",
    startTime: 0,
    endTime: 0,
    purpose: "",
    location: "",
    maxAdvanceDays: 1,
    usageDurationDays: 1,
    frequencyLimit: 1,
  };
  // 清空已预约时间段数据
  existingReservations.value = [];
  bookingFormRef.value?.clearValidate();
  bookingDialogVisible.value = false;
}
const bookingFormRules = {
  dateRange: [{ required: true, message: "请选择预约时间", trigger: "blur" }],
  purpose: [{ required: true, message: "请输入用途", trigger: "blur" }],
  location: [{ required: true, message: "请输入使用位置", trigger: "blur" }],
  usageDurationDays: [
    { required: true, message: "请输入使用时长", trigger: "blur" },
  ],
  maxAdvanceDays: [
    { required: true, message: "请输入最大提前量", trigger: "blur" },
  ],
  frequencyLimit: [
    { required: true, message: "请输入频次限制", trigger: "blur" },
  ],
};

// 查看审批进度
const auditProgressDialogVisible = ref(false);
const auditProgressLoading = ref(false);
const auditProgress = ref<AuditProgressType[]>([]);

// 查看审批进度
function getApplyAuditProgress(id: string) {
  if (auditProgressLoading.value) {
    return;
  }
  auditProgressLoading.value = true;

  getApplicationDetailAPI(id)
    .then((_data) => {
      const data = _data as any;
      auditProgress.value = data.approvalRecords || [];
      auditProgress.value.unshift({
        id: "",
        stage: "",
        stageDescription: "提交申请",
        status: "COMPLETED",
        statusDescription: "已完成",
        result: null,
        resultDescription: "",
        comment: "",
        approverCode: "",
        approverName: "",
        approvalTime: "",
        priority: 0,
      });
    })
    .catch(() => {
      ElMessage.error("获取审批进度失败");
    })
    .finally(() => {
      auditProgressLoading.value = false;
    });
}
// 查看预约审批进度
const auditReservationProgressDialogVisible = ref(false);
const auditReservationProgressLoading = ref(false);
const auditReservationProgress = ref<any[]>([]);
const reservationStatusMap = ref({
  IN_PROGRESS: "进行中",
  COMPLETED: "已完成",
  NOT_STARTED: "未开始",
});
function getReservationAuditProgress(id: string) {
  if (auditReservationProgressLoading.value) {
    return;
  }
  auditReservationProgressLoading.value = true;
  getReservationByIdAPI(id)
    .then((_data) => {
      const data = _data as any;
      auditReservationProgress.value = data.approvalRecords || [];
      auditReservationProgress.value.unshift({
        id: "",
        stage: "",
        approverInfo: {
          name: "提交申请",
        },
        status: "COMPLETED",
        result: null,
        resultDescription: "",
        comment: "",
        approverCode: "",
        approverName: "",
        approvalTime: "",
        priority: 0,
      });
    })
    .catch(() => {
      ElMessage.error("获取审批进度失败");
    })
    .finally(() => {
      auditReservationProgressLoading.value = false;
    });
}

function auditProgressHandle(row: any, type: string) {
  if (type === "apply") {
    auditProgressDialogVisible.value = true;
    getApplyAuditProgress(row?.applicationProcesses[0]?.id);
  } else if (type === "booking") {
    auditReservationProgressDialogVisible.value = true;
    getReservationAuditProgress(row?.reservationProcesses[0]?.id);
  }
}

// 归还
const returnDialogVisible = ref(false);
const returnLoading = ref(false);
const returnFormRef = ref();
const returnForm = ref({
  reservationId: "",
  userCode: userInfo.userCode || "",
  returnNote: "",
});
const currentReturnRow = ref<any>(null);
function returnHandle(row: any) {
  returnDialogVisible.value = true;
  currentReturnRow.value = row;
  returnForm.value.reservationId = row.reservationProcesses[0]?.id || "";
}
function submitReturnForm() {
  if (returnLoading.value) return;
  returnLoading.value = true;
  returnDeviceAPI(returnForm.value)
    .then(() => {
      ElMessage.success("归还设备成功");
      resetReturnForm();
      getEquipmentList();
    })
    .catch(() => {
      ElMessage.error("归还设备失败");
    })
    .finally(() => {
      returnLoading.value = false;
    });
}

// 开始使用
function useDeviceHandle(row: any) {
  ElMessageBox.confirm("确定开始使用设备吗？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    updateUseStatusAPI({
      reservationId: row.reservationProcesses[0]?.id || "",
      userCode: userInfo.userCode || "",
      useStatus: "IN_USE",
    }).then(() => {
      ElMessage.success("开始使用设备成功");
      getEquipmentList();
    });
  });
}

// 重置表单
function resetReturnForm() {
  returnForm.value = {
    reservationId: "",
    userCode: userInfo.userCode || "",
    returnNote: "",
  };
  returnFormRef.value?.clearValidate();
  returnDialogVisible.value = false;
}
</script>

<style scoped lang="scss">
#EquipmentBookingIngPage {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.title-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 2rem;
  padding-left: 1rem;
  color: $color_brand;
  font-size: $font-size-block-title;
}
.title-wrapper::before {
  position: absolute;
  left: 0;
  top: 50%;
  display: block;
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background-color: $color_brand;
  transform: translateY(-50%);
}
.search-wrapper {
  flex-shrink: 0;
  padding: 1.5rem;
  background-color: #fff;
  border-bottom: 1px solid $border-color-primary;
  .content-wrapper {
    position: relative;
    display: flex;
    padding-top: 1rem;
    padding-left: 1rem;
  }
  .search-item {
    display: flex;
    align-items: center;
    padding-right: 2rem;
    .item-label {
      display: inline;
      padding-right: 1rem;
      flex-wrap: nowrap;
      text-align: right;
      color: $text-color-regular;
    }
    .item-input {
      width: 20rem;
    }
  }
  .search-btn {
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background-color: $color_brand;
    color: #fff;
    border-radius: 0.5rem;
    cursor: pointer;
  }
  .add-btn {
    position: absolute;
    right: 3.2rem;
    top: 1rem;
    display: flex;
    align-items: center;
    padding: 0.5rem 1.5rem;
    background-color: $color_brand;
    color: #fff;
    border-radius: 0.5rem;
    cursor: pointer;
  }
}
.data-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background-color: #fff;
  .table-wrapper {
    margin-top: 1rem;
    padding-left: 1rem;
    flex: 1;
    min-height: 0;
  }
  .table-btn {
    display: inline-flex;
    align-items: center;
    background-color: $color_brand;
    color: #fff;
    margin-left: 0.5rem;
    padding: 0 1rem;
    border-radius: 0.5rem;
    font-size: $font-size-base-btn-text;
    cursor: pointer;
  }
  .table-btn:first-child {
    margin-left: 0;
  }
  .table-btn:hover {
    text-decoration: underline;
  }
  .signal-status.IDLE {
    color: #999;
  }
  .signal-status.RESERVEING {
    color: $color_warning;
  }
  .signal-status.IN_USE {
    color: $color_success;
  }
  .signal-status.REPAIRING {
    color: $color_danger;
  }
  .signal-status.DAMAGED {
    color: $color_danger;
  }
  .signal-status.SCRAPPED {
    color: $color_danger;
  }

  .equipment-name-wrapper {
    display: flex;
    align-items: center;
    .equipment-photo {
      width: 5rem;
      height: 5rem;
      border-radius: 0.5rem;
      margin-right: 1rem;
    }
    .equipment-info-wrapper {
      display: flex;
      flex-direction: column;
      .equipment-name {
        padding-top: 0.5rem;
        font-size: $font-size-base;
      }
      .equipment-sn {
        font-size: $font-size-tips;
        color: $text-color-secondary;
      }
    }
  }
}

// 分页区域样式
.pagination-wrapper {
  flex-shrink: 0;
}

// 审批进度样式
.audit-progress-container {
  .progress-steps {
    .progress-step {
      display: flex;
      align-items: flex-start;
      position: relative;
      padding-bottom: 2rem;

      &:last-child {
        padding-bottom: 0;
      }

      .step-indicator {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-right: 1rem;
        padding-top: 0.6rem;

        .step-circle {
          width: 1rem;
          height: 1rem;
          border-radius: 50%;
          border: 2px solid $border-color-primary;
          background-color: #fff;
          z-index: 2;
        }

        .step-line {
          position: absolute;
          top: 0.6rem;
          bottom: 0;
          width: 1px;
          background-color: $border-color-primary;
        }
      }

      .step-content {
        flex: 1;
        padding-top: 0.125rem;

        .step-title {
          font-size: $font-size-base;
          font-weight: 500;
          color: $text-color-regular;
          margin-bottom: 0.25rem;
        }
        .step-time {
          font-size: $font-size-tips;
          color: $text-color-secondary;
          margin-bottom: 0.25rem;
        }

        .step-handler {
          font-size: $font-size-tips;
          color: $text-color-secondary;
        }
        .step-comment {
          font-size: $font-size-tips;
          color: $text-color-secondary;
        }
      }

      // 已完成状态
      &.COMPLETED {
        .step-indicator {
          .step-circle {
            background-color: #52c41a;
            border-color: #52c41a;
          }
          .step-line {
            background-color: #52c41a;
          }
        }
        .step-content .step-title {
          color: #52c41a;
        }
      }

      // 进行中状态
      &.IN_PROGRESS {
        .step-indicator {
          .step-circle {
            background-color: #1890ff;
            border-color: #1890ff;
          }
          .step-line {
            background-color: #d9d9d9;
          }
        }
        .step-content .step-title {
          color: #1890ff;
        }
      }

      // 待处理状态
      &.step-pending {
        .step-indicator {
          .step-circle {
            background-color: #fff;
            border-color: #d9d9d9;
          }
          .step-line {
            background-color: #d9d9d9;
          }
        }
        .step-content .step-title {
          color: #999;
        }
      }
    }
  }
}

// 申请设备
.handle-message {
  margin-bottom: 2rem;
  padding-left: 3rem;
  font-size: $font-size-page-menu;
  color: $color_brand;
}

.reservation-tips {
  margin-bottom: 2rem;
  padding: 1rem;
  background-color: #f5f7fa;
  border-radius: 0.5rem;
  border-left: 4px solid $color_warning;

  .tips-title {
    font-size: $font-size-base;
    font-weight: 500;
    color: $text-color-regular;
    margin-bottom: 0.5rem;
  }

  .tips-content {
    .reservation-item {
      font-size: $font-size-tips;
      color: $text-color-secondary;
      margin-bottom: 0.25rem;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}

:deep(.el-form-item__content) {
  flex-wrap: nowrap;
}
</style>
